import React from 'react'
import PropTypes from 'prop-types'

class Counter extends React.Component{

    constructor(props) {
        super(props)
        // 复用数据
        this.state = {
             count: 0
        }
    }
    // 复用操作数据的方法
    handleCount = () => {
        this.setState({
            count: this.state.count +1
        })
    }

    render () {
        console.log(this.props)
        return (
            <div>
                {this.props.render(this.state.count, this.handleCount)}
                {/* {this.props.children(this.state.count, this.handleCount)} */}
            </div>
        )
    }

}

Counter.propTypes ={
    children: PropTypes.func.isRequired
}

export default Counter